home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / pas_all.zip / TI232.ASC < prev    next >
Text File  |  1991-09-11  |  9KB  |  397 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.   PRODUCT : TURBO PASCAL                               NUMBER : 232
  10.   VERSION : ALL
  11.        OS : PC-DOS
  12.      DATE : August 1, 1986                               PAGE : 1/6
  13.     TITLE : INTERRUPT 25 & 26 - ABSOLUTE DISK READ AND WRITE
  14.  
  15.  
  16.  
  17.  
  18.   The following example routines are public domain programs that
  19.   have been uploaded to our Forum on CompuServe. As a courtesy to
  20.   our users that do not have immediate access to CompuServe,
  21.   Technical Support distributes these routines free of charge.
  22.  
  23.   However, because these routines are public domain programs, not
  24.   developed by Borland International, we are unable to provide any
  25.   technical support or assistance using these routines. If you need
  26.   assistance using these routines, or are experiencing
  27.   difficulties, we recommend that you log onto CompuServe and
  28.   request assistance from the Forum members that developed these
  29.   routines.
  30.  
  31.   Turbo Pascal's Intr procedure cannot call MS-DOS interrupts 25H
  32.   and 26H because they do not leave the CPU flags on the stack.
  33.   This set of functions allows you to call those interrupts, which
  34.   are Absolute Disk Read and Absolute Disk Write, by using the
  35.   following functions ReadSectors and WriteSectors, respectively.
  36.  
  37.   Both functions are called with the same parameters:
  38.        Buffer: a buffer large enough to hold NumberSectors 512
  39.        byte sectors.
  40.        Drive: the drive number. 0 is A:, 1 is B:, and so on.
  41.        NumberSectors: the number of sectors to transfer.
  42.        LogicalSector: the first logical sector number to transfer.
  43.  
  44.   Be sure that the Buffer is large enough to hold 512 times
  45.   NumberSectors bytes of data. Failure to do so will surely lead
  46.   to bugs that are difficult to solve.
  47.  
  48.   The integer return value is the error code returned by MS-DOS.
  49.   "0" indicates a successful transfer, all other values are errors.
  50.   See a DOS Technical Reference Manual for translations.
  51.  
  52.   A small sample program is provided. It is a minimal disk editor
  53.   and is intended as an example only, though it provides the basis
  54.   for a complete disk editor/utility. The example is commented out
  55.   -- you must remove the line with the "(*" on it.
  56.  
  57.   USE WITH CAUTION!
  58.  
  59.   {$C-}
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.   PRODUCT : TURBO PASCAL                               NUMBER : 232
  76.   VERSION : ALL
  77.        OS : PC-DOS
  78.      DATE : August 1, 1986                               PAGE : 2/6
  79.     TITLE : INTERRUPT 25 & 26 - ABSOLUTE DISK READ AND WRITE
  80.  
  81.  
  82.  
  83.  
  84.   {  Remove  the  leading  * for better keyboard  response  in  the
  85.   example program }
  86.  
  87.   Function __ReadWriteSectors(Var Buffer;
  88.                  Drive, NumberSectors, LogicalSector: Integer;
  89.                  WriteFlag: Byte): Integer;
  90.   Var Result: Integer;
  91.   Begin
  92.     Result:=0;
  93.     Inline($8A/$86/ Drive /      { MOV  AL,[BP+Drive]            }
  94.       $8B/$8E/ NumberSectors /   { MOV  CX,[BP+NumberSectors]    }
  95.       $8B/$96/ LogicalSector /   { MOV  DX,[BP+LogicalSector]    }
  96.       $55/                       { PUSH BP                       }
  97.       $1E/                       { PUSH DS                       }
  98.       $C5/$9E/ Buffer /          { LDS  BX,[BP+Buffer]           }
  99.       $80/$BE/ WriteFlag /$01/   { CMP  BYTE PTR [BP+WriteFlag],1  }
  100.       $74/$04/                   { JE   Write                      }
  101.       $CD/$25/                   { INT  25H                        }
  102.       $EB/$02/                   { JMP  WrapUp                     }
  103.       $CD/$26/                   {Write: INT 26H                   }
  104.       $5B/
  105.                           {WrapUp:POP  BX ;Dispose of flags }
  106.       $1F/                       {       POP  DS                 }
  107.       $5D/                       {       POP  BP                 }
  108.       $73/$04/                   {       JNB  Ok                 }
  109.       $89/$86/ Result            {       MOV  [BP+Result],AX     }
  110.       );                         {Ok:                            }
  111.     __ReadWriteSectors:=Result;
  112.   End;
  113.  
  114.   Function ReadSectors(Var Buffer; Drive, NumberSectors,
  115.                        LogicalSector: Integer): Integer;
  116.     Begin
  117.       ReadSectors:=
  118.      __ReadWriteSectors(Buffer,Drive,NumberSectors,
  119.                         LogicalSector,0);
  120.     End;
  121.  
  122.   Function WriteSectors(Var Buffer; Drive, NumberSectors,
  123.                         LogicalSector: Integer): Integer;
  124.     Begin
  125.       WriteSectors:=
  126.         __ReadWriteSectors(Buffer,Drive,NumberSectors,
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.   PRODUCT : TURBO PASCAL                               NUMBER : 232
  142.   VERSION : ALL
  143.        OS : PC-DOS
  144.      DATE : August 1, 1986                               PAGE : 3/6
  145.     TITLE : INTERRUPT 25 & 26 - ABSOLUTE DISK READ AND WRITE
  146.  
  147.  
  148.  
  149.  
  150.                            LogicalSector,1);
  151.     End;
  152.  
  153.   { Example program.  Delete next line to enable it: }
  154.   (*
  155.  
  156.   {$R+}
  157.  
  158.   Type
  159.     Str=String[4];
  160.  
  161.   Function Int2Hex2(B: Byte): Str;
  162.     Const H: Array [0..15] Of Char='0123456789ABCDEF';
  163.     Begin
  164.       Int2Hex2:=H[B Shr 4]+H[B And 15];
  165.     End;
  166.  
  167.   Function Int2Hex4(I: Integer): Str;
  168.     Const H: Array [0..15] Of Char='0123456789ABCDEF';
  169.     Begin
  170.       Int2Hex4:=H[I Shr 12]+H[(I Shr 8) And 15]+
  171.                 H[(I Shr 4) And 15]+H[I And 15];
  172.     End;
  173.  
  174.   Function Hex2Int1(C: Char): Byte;
  175.     Begin
  176.       Case Upcase(C) Of
  177.         '0'..'9': Hex2Int1:=Ord(C) And 15;
  178.         'A'..'F': Hex2Int1:=Ord(C) And 15+9;
  179.         Else Hex2Int1:=0;
  180.        End;
  181.     End;
  182.  
  183.   Function Hex2Int4(S: Str; Default: Integer): Integer;
  184.     Var I: Integer;
  185.     Begin
  186.       If S='' Then Hex2Int4:=Default
  187.       Else
  188.        Begin
  189.         I:=0;
  190.         While S<>'' Do
  191.          Begin
  192.           I:=I Shl 4 + Hex2Int1(S[1]);
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.   PRODUCT : TURBO PASCAL                               NUMBER : 232
  208.   VERSION : ALL
  209.        OS : PC-DOS
  210.      DATE : August 1, 1986                               PAGE : 4/6
  211.     TITLE : INTERRUPT 25 & 26 - ABSOLUTE DISK READ AND WRITE
  212.  
  213.  
  214.  
  215.  
  216.           Delete(S,1,1);
  217.          End;
  218.         Hex2Int4:=I;
  219.        End;
  220.     End;
  221.  
  222.   Procedure ShowSector(Var S);
  223.     Var Buffer: Array [0..31,0..15] Of Byte Absolute S;
  224.         I,J: Integer;
  225.         B: Byte;
  226.     Begin
  227.       For I:=0 To 31 Do
  228.        Begin
  229.         Write(Int2Hex4(I Shl 4),' |  ');
  230.         For J:=0 To 15 Do
  231.          Begin
  232.           Write(Int2Hex2(Buffer[I,J]),' ');
  233.           If J And 3=3 Then Write(' ');
  234.          End;
  235.         Write('| ');
  236.         For J:=0 To 15 Do
  237.          Begin
  238.           B:=Buffer[I,J];
  239.           If B<127 Then NormVideo
  240.           Else LowVideo;
  241.           B:=B And $7F;
  242.           If B<32 Then B:=Ord('.');
  243.           Write(Chr(B));
  244.          End;
  245.         NormVideo;
  246.         WriteLn;
  247.        End;
  248.     End;
  249.  
  250.   Var
  251.     Buffer: Array [0..511] Of Byte;
  252.     DR,LS,Result,C: Integer;
  253.     W: Char;
  254.     V: Str;
  255.     Changed: Boolean;
  256.  
  257.   Begin
  258.     FillChar(Buffer,SizeOf(Buffer),'z');
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.   PRODUCT : TURBO PASCAL                               NUMBER : 232
  274.   VERSION : ALL
  275.        OS : PC-DOS
  276.      DATE : August 1, 1986                               PAGE : 5/6
  277.     TITLE : INTERRUPT 25 & 26 - ABSOLUTE DISK READ AND WRITE
  278.  
  279.  
  280.  
  281.  
  282.     Repeat
  283.       DR:=-1;
  284.       Write('Enter the drive # to read (CR to end): ');
  285.       ReadLn(DR);
  286.       If DR In [0..25] Then
  287.        Begin
  288.         Write('Enter the logical sector # to read: ');
  289.         ReadLn(LS);
  290.         Result:=ReadSectors(Buffer,DR,1,LS);
  291.         WriteLn('Result code = ',Result);
  292.         Changed:=False;
  293.         Repeat
  294.           ShowSector(Buffer);
  295.           Write('Enter the number of the byte to change ');
  296.           Write(' (0-1FF, CR to end): ');
  297.           ReadLn(V);
  298.           C:=Hex2Int4(V,-1);
  299.           If (C>0) And (C<512) Then
  300.            Begin
  301.             Write('Enter new value [',Int2Hex2(Buffer[C]),']: ');
  302.             ReadLn(V);
  303.             If Length(V)>1 Then
  304.               If V[1] In ['''','"'] Then Buffer[C]:=Ord(V[2])
  305.               Else Buffer[C]:=Hex2Int4(V,Buffer[C])
  306.             Else Buffer[C]:=Hex2Int4(V,Buffer[C]);
  307.             Changed:=True;
  308.            End
  309.           Else C:=-1;
  310.         Until C=-1;
  311.  
  312.         If Changed Then
  313.          Begin
  314.           Write('Write changes back to drive ',DR,',');
  315.           Write ('logical sector #',LS,' (Y/N)? ');
  316.           ReadLn(W);
  317.           If Upcase(W)='Y' Then
  318.            Begin
  319.             Result:=WriteSectors(Buffer,DR,1,LS);
  320.             WriteLn('Result code = ',Result);
  321.            End;
  322.          End;
  323.        End
  324.       Else DR:=-1;
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.   PRODUCT : TURBO PASCAL                               NUMBER : 232
  340.   VERSION : ALL
  341.        OS : PC-DOS
  342.      DATE : August 1, 1986                               PAGE : 6/6
  343.     TITLE : INTERRUPT 25 & 26 - ABSOLUTE DISK READ AND WRITE
  344.  
  345.  
  346.  
  347.  
  348.     Until DR=-1;
  349.   End.
  350.   (**)
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.